package com.ruoyi.rsikManage.MonitorPoint.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.ruoyi.common.GenericMethodsService;
import com.ruoyi.common.core.domain.entity.SysDept;
import com.ruoyi.rsikManage.MonitorPoint.domain.TMonitorPointRequest;
import org.springframework.stereotype.Service;
import com.ruoyi.rsikManage.MonitorPoint.mapper.TMonitorPointMapper;
import com.ruoyi.rsikManage.MonitorPoint.domain.TMonitorPoint;
import com.ruoyi.rsikManage.MonitorPoint.service.ITMonitorPointService;

/**
 * 设备Service业务层处理
 *
 * @author sxygsj
 * @date 2024-11-29
 */
@Service
public class TMonitorPointServiceImpl implements ITMonitorPointService
{
    private final TMonitorPointMapper tMonitorPointMapper;
    private final GenericMethodsService genericMethodsService;

    // 构造函数
    public TMonitorPointServiceImpl(TMonitorPointMapper tMonitorPointMapper, GenericMethodsService genericMethodsService) {
        this.tMonitorPointMapper = tMonitorPointMapper;
        this.genericMethodsService = genericMethodsService;
    }


    /**
     * 查询设备
     *
     * @param apeId 设备主键
     * @return 设备
     */
    @Override
    public TMonitorPoint selectTMonitorPointByApeId(String apeId)
    {
        return tMonitorPointMapper.selectTMonitorPointByApeId(apeId);
    }

    /**
     * 查询设备列表
     *
     * @param tMonitorPointRequest 设备
     * @return 设备
     */
    @Override
    public List<TMonitorPoint> selectTMonitorPointList(TMonitorPointRequest tMonitorPointRequest )
    {
        List<TMonitorPoint> tMonitorPoints = tMonitorPointMapper.selectTMonitorPointList(tMonitorPointRequest);
        Map<Long, SysDept> deptMap = genericMethodsService.getDeptMap();
        // 遍历 reportApprovals 列表，根据 unitCode 匹配 deptName 并赋值给 unitName
        for (TMonitorPoint tMonitorPoint : tMonitorPoints) {
            SysDept dept = deptMap.get(tMonitorPoint.getUnitCode());
            if (dept != null) {
                tMonitorPoint.setUnitName(dept.getDeptName());
            }
        }
        return tMonitorPoints;
    }

    /**
     * 新增设备
     *
     * @param tMonitorPoint 设备
     * @return 结果
     */
    @Override
    public int insertTMonitorPoint(TMonitorPoint tMonitorPoint)
    {
        return tMonitorPointMapper.insertTMonitorPoint(tMonitorPoint);
    }

    /**
     * 修改设备
     *
     * @param tMonitorPoint 设备
     * @return 结果
     */
    @Override
    public int updateTMonitorPoint(TMonitorPoint tMonitorPoint)
    {
        return tMonitorPointMapper.updateTMonitorPoint(tMonitorPoint);
    }

    /**
     * 批量修改设备
     *
     * @param tMonitorPoints 设备
     * @return 结果
     */
    @Override
    public int batchUpdateTMonitorPoint(List<TMonitorPoint> tMonitorPoints)
    {
        return tMonitorPointMapper.batchUpdateTMonitorPoint(tMonitorPoints);
    }

    /**
     * 批量删除设备
     *
     * @param apeIds 需要删除的设备主键
     * @return 结果
     */
    @Override
    public int deleteTMonitorPointByApeIds(String[] apeIds)
    {
        return tMonitorPointMapper.deleteTMonitorPointByApeIds(apeIds);
    }

    /**
     * 删除设备信息
     *
     * @param apeId 设备主键
     * @return 结果
     */
    @Override
    public int deleteTMonitorPointByApeId(String apeId)
    {
        return tMonitorPointMapper.deleteTMonitorPointByApeId(apeId);
    }

    @Override
    public HashMap<String, Integer> getStatusCount(TMonitorPointRequest tMonitorPointRequest) {
        return tMonitorPointMapper.getStatusCount(tMonitorPointRequest);    }

    @Override
    public HashMap<String, Integer> getTypeCount(TMonitorPointRequest tMonitorPointRequest) {
        return null;
    }
}
